import { depoColldown } from "utils/constants/definetypes";
import { APollingTask, CacheData } from "../../PollingStation";

export class CacheDataDepo<T extends ICacheDepo=ICacheDepo> extends CacheData<T>
{

}

export class CacheDepoTask<T = CacheDataDepo<ICacheDepo>> extends APollingTask<T>
{
    // roomName!:string;

    Update(...arg:any[]): void
    {
        // this.roomName = arg[0];
        const room = Game.rooms[this.code];
        if(room)
        {
            const depos = room.find(FIND_DEPOSITS,{filter:d=>d.lastCooldown<depoColldown});
            const cachedata:ICacheDepo[]  = _.map(depos,item=>{
                const ret:ICacheDepo= {
                    id:item.id  ,
                    pos:item.pos,
                    type:item.depositType,
                    lastcooldown:item.lastCooldown
                    // lastcooldown:item.lastCooldown,
                    // decay:item.ticksToDecay
                } ;
                return ret;
            });
            this.value = new CacheDataDepo<ICacheDepo>(cachedata) as unknown as  T;

            if(cachedata.length>0)
            {
                this.lastupdate = Game.time + 200;
            }
            else
            {
                this.lastupdate = Game.time + 100;
            }
        }
        else
        {
            this.value =undefined;
        }
    }

}
